package com.tjy.springboot.config;

import com.alibaba.druid.support.http.StatViewServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
//此注解表示 此类是一个配置类
@Configuration
public class DruidConfig {

    @Bean
    public ServletRegistrationBean<StatViewServlet> druidStaViewServlet(){
        ServletRegistrationBean<StatViewServlet> registrationBean = new ServletRegistrationBean<>(new StatViewServlet(),"/druid/*");
        //ip白名单(没有配置或为空，运行访问)
//        registrationBean.addInitParameter("allow","127.0.0.1");
        //ip黑名单(存在共同时，deny优先于allow)
//        registrationBean.addInitParameter("deny","");
        //设置登录druid后台账号
        registrationBean.addInitParameter("loginUsername","druid");
        //设置登录druid后台密码
        registrationBean.addInitParameter("loginPassword","druid");
        registrationBean.addInitParameter("resetEnable","false");
        return registrationBean;
    }
}
